<?php
// Make sure we're logged in (send us to the front page if not)
	gatekeeper();
// Make sure action is secure
  action_gatekeeper();
// Get input data
	$native = get_input('pelnative');
	$access = get_input('access_id');
  $guid = get_input('guid');
  $pel= get_entity($guid);

  if ($pel->getSubtype() == "pel" && $pel->canEdit()){
   	// Make sure the title / description aren't blank
		if (empty($native)){
			register_error(elgg_echo("pel:blank"));
			forward("mod/pel/edit.php");
	// Otherwise, save the pel
		}
    else{
      // For now, set its access to public (we'll add an access dropdown shortly)
			$pel->access_id = $access;
      // Set its description appropriately
			$pel->description = $native;
      // Before we can set metadata, we need to save the pel
			if (!$pel->save()){
				register_error(elgg_echo("pel:error"));
				forward("mod/pel/edit.php");
			}
	// Success message
			system_message(elgg_echo("pel:pelsaved"));
	// Remove the pel cache
			unset($_SESSION['pelnative']);
	// Forward to the main pel page
			forward("mod/pel/?username=" . $_SESSION['user']->username);
		}
	}
?>